package com.lzx.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.lzx.mapper.nydsj.BjxxMapper;
import com.lzx.model.User;
import com.lzx.model.nydsj.*;
import com.lzx.service.UserService;
import com.lzx.service.nydsj.*;
import com.lzx.utils.SessionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.sql.SQLException;
import java.util.List;


@RestController
@RequestMapping("/nydsj")
public class NydsjController {
    @Autowired
    private LsjgService lsjgService;
    @Autowired
    private SdclService sdclService;
    @Autowired
    private TrphzService trphzService;
    @Autowired
    private BjxxMapper bjxxMapper;
    @Autowired
    private ZzmjService zzmjService;
    @Autowired
    private HfService hfService;
    @Autowired
    private YxjService yxjService;
    @Autowired
    private YxlService yxlService;
    @Autowired
    private ZhsjService zhsjService;
    @Autowired
    private TryjzService tryjzService;
    @Autowired
    private UserService userService;

    @RequestMapping("/nydsj.html")
    public ModelAndView nydsj(HttpServletRequest request) {
        ModelAndView mv = new ModelAndView("system/nydsj");
        User user = SessionUtil.getUser(request);
        return mv;
    }

    @RequestMapping("/lsjg.html")
    public String lsjg() {
        List<Lsjg> list = lsjgService.findlsjg();
        List<Lsjg> lsjgListGROUP = lsjgService.findLsjgListGROUP();//查品类
        String s = JSON.toJSONString(list);
        String s1 = JSON.toJSONString(lsjgListGROUP);
        JSONObject jsonstr = new JSONObject();
        jsonstr.put("name", s1);
        jsonstr.put("data", s);
        return jsonstr.toJSONString();
    }

    @RequestMapping("/sdcl.html")
    public String sdcl(){
        List<Sdcl> list =sdclService.findlist();
        List<Sdcl> sdclListGroup = sdclService.findlistGroup();
        String s = JSON.toJSONString(list);
        String s1 = JSON.toJSONString(sdclListGroup);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("name",s1);
        jsonObject.put("data",s);
        return jsonObject.toJSONString();
    }

    @RequestMapping("/trphz.html")
    public String trphz(){
        List<Trphz> list = trphzService.findList();
        return JSON.toJSONString(list);
    }
    @RequestMapping("/bjxx.html")
    public String bjxx(){
        List<Bjxx> list = bjxxMapper.findlist();
        return JSON.toJSONString(list);
    }
    @RequestMapping("/zzmj.html")
    public String zzmj(){
        List<Zzmj> list = zzmjService.findList();

            String b="";
        for (int i = 0; i <list.size() ; i++) {
            String a="";
             a = list.get(i).getArea();
                for (int j = 0; j <6 ; j++) {
                    if(a.length()<6){
                    a = "0"+a;
                    list.get(i).setArea(a);
                }
                }
        }
        return JSON.toJSONString(list);
    }
    @RequestMapping("/hf.html")
    public String hf(){
        List<Hf> list = hfService.findlist();
        return JSON.toJSONString(list);
    }
    @RequestMapping("/yxj.html")
    public String yxj(){
        List<Yxj> list = yxjService.findList();
        return JSON.toJSONString(list);
    }
    @RequestMapping("/yxl.html")
    public String yxl(){
        List<Yxl> list = yxlService.findList();
        return JSON.toJSONString(list);
    }
    @RequestMapping("/zhsj.html")
    public String zhsj(){
        List<Zhsj> list = zhsjService.findList();
        return JSON.toJSONString(list);
    }
    @RequestMapping("/tryjz.html")
    public String tryjz(){
        List<Tryjz> list = tryjzService.findList();
        return JSON.toJSONString(list);
    }
    @RequestMapping("/ditu.html")
    public  String ditu(HttpServletRequest request) throws SQLException {
        User user = SessionUtil.getUser(request);
        String userName = user.getUsername();
        System.out.println("@@@@@@@@@@@"+userName);
        User user1=userService.queryByUserName(userName);
        System.out.println("@!!!!!!!"+user1.toString());
        System.out.println("############"+user1.getUserId());
        String tupian=user1.getUserId();
        return JSON.toJSONString(tupian);
    }
}
